#!/bin/bash

# Get the directory where the script is located
SCRIPT_DIR=$(dirname "$(realpath "$0")")

# Define the test function
run_test() {
  echo "Generating configuration file: $CONF_PATH"
  python "$SCRIPT_DIR/prepare_employees.py" || { echo "Python script execution failed"; return 1; }
  for i in $(seq 5 5 100); do
    # Calculate the ratio and format it to two decimal places
    RATIO=$(echo "scale=2; $i / 100" | bc | sed 's/^\./0./')

    # Configuration file path
    CONF_PATH="$SCRIPT_DIR/conf/employees_ratio_${RATIO}.yaml"

    # Execute the Go test program
    echo "Running test: $CONF_PATH (Ratio: ${RATIO})"
    go run "$SCRIPT_DIR/main.go" --config "$CONF_PATH" --test "employees_ratio_${RATIO}" || { echo "Go program execution failed"; return 1; }
  done
}

# Run the test 20 times
for i in $(seq 1 20); do
  echo "===== Starting test iteration $i ====="
  run_test || { echo "Test failed"; exit 1; }
done

echo "All tests completed!"